<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class IndexController extends Controller
{
    public function getIndex(Request $request)
    {   
    	//登录计数
    	$volume=DB::table('volume')->where('id',1)->first()->volume;
    	$volume+=1;
    	DB::table('volume')->where('id',1)->update(['volume'=>$volume]);

    	//福利标签
    	$fu=DB::table("label")->get();
    	//工资
    	$salary=DB::table('pms')->get();
    	//公司性质
    	$type=DB::table('corptype')->get();
    	//学历
    	$major=DB::table("er")->get();
    	//职位性质
    	$etype=DB::table('etype')->get();

        $data=DB::table('recruit')
             ->leftJoin('regioncate','recruit.r_id','=','regioncate.id')
             ->leftJoin('er','recruit.er_id','=','er.id')
             ->leftJoin('we','recruit.w_id','=','we.id')
             ->leftJoin('enterprises','recruit.e_id','=','enterprises.id')
             ->leftJoin('pms','recruit.pms_id','=','pms.id')
             ->leftJoin('corptype','enterprises.corptype','=','corptype.id')
             ->leftJoin('corpsize','enterprises.corpsize','=','corpsize.id')
             ->select('recruit.*','corptype.name as cname','regioncate.name','enterprises.compname','enterprises.companydetail','pms.value','corpsize.name as size','er.value as major','we.value as nian')
             ->where('recruit.status',1)
             ->paginate($request->input('pages',10));

    
    	return view('Home.index',['fu'=>$fu,'salary'=>$salary,'type'=>$type,'major'=>$major,'etype'=>$etype,'data'=>$data,'request'=>$request->all()]);
    }

    //搜索
    public function getSearch(Request $request)
    {
    	// dd($request->all());

        //福利标签
        $fu=DB::table("label")->get();
        //工资
        $salary=DB::table('pms')->get();
        //公司性质
        $type=DB::table('corptype')->get();
        //学历
        $major=DB::table("er")->get();
        //职位性质
        $etype=DB::table('etype')->get();
        $di=explode('+',$request->jl);
        // dd($di);
        $key=$request->kw;

        $data=DB::table('recruit')
             ->leftJoin('regioncate','recruit.r_id','=','regioncate.id')
             ->leftJoin('er','recruit.er_id','=','er.id')
             ->leftJoin('we','recruit.w_id','=','we.id')
             ->leftJoin('enterprises','recruit.e_id','=','enterprises.id')
             ->leftJoin('pms','recruit.pms_id','=','pms.id')
             ->leftJoin('corptype','enterprises.corptype','=','corptype.id')
             ->leftJoin('corpsize','enterprises.corpsize','=','corpsize.id')
             ->select('recruit.*','corptype.name as cname','regioncate.name','enterprises.compname','enterprises.companydetail','pms.value','corpsize.name as size','er.value as major','we.value as nian')
             ->where('recruit.workname','like','%'.$key.'%')
             ->where('recruit.status',1)
             ->whereIn('regioncate.name',$di)
             // ->get();
             ->paginate($request->input('pages',10));
        
        return view('home/index',['fu'=>$fu,'salary'=>$salary,'type'=>$type,'major'=>$major,'etype'=>$etype,'data'=>$data,'request'=>$request->all()]);
    }

    public function postAjaxjl(Request $request)
    {
        if(session('user')['is_login']=1 && !empty(session('user')['is_login']))
        {

         $data['ent_id']=$request->en;
        $data['rec_id']=$request->re;
        $data['int_id']=session('user')['id'];
        $data['res_id']=DB::table('resume')->where("inter_id",$data['int_id'])->first()->id;
        $data['status']=0;
        
        $res=DB::table('resume_recruit')->insert($data);
        if($res)
        {
            return response()->json(1);
        }else
        {
            return response()->json(0);
        }

        }else
        {
            return response()->json(2);
        }
       

    }

}
